import java.util.Arrays;
import java.util.Scanner;

public class C {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m + 10];
		int[] h = new int[n + 10]; // 行
		int[] l = new int[n + 10];
		int[] zd = new int[n * n + 200000]; // 正对角线
		int[] fd = new int[n * n + 200000]; // 反对角线
		
		// 是n*n的数组 阵列
		for(int i = 1; i <= m; i ++ ) {
			a[i] = sc.nextInt();
			//转换位行和列的形式
			int x = a[i] / n + 1;
			if(a[i] % n == 0)x -= 1;
			
			int y = a[i] % n;
			if(y == 0)y = n;
			h[x] += 1;
			l[y] += 1;
			zd[y - x + 200000] += 1;
			fd[x + y] += 1;
			
			if(h[x] == n || l[y] == n || zd[y - x + 200000] == n || fd[x + y] == n) {
				System.out.print(i);
				return;
			}
		}
		System.out.print(-1);
	}
}
